<template>
  <div class="photoinfo-container">
    <!-- <h3>图片详情界面--- {{ id }}</h3> -->

    <h3 class="title">{{ photoinfo.title }}</h3>
    <p class="info">
      <span>发表时间： {{ photoinfo.add_time|dataFormat }}</span>
      <span>点击：{{ photoinfo.click }}次</span>
    </p>

    <hr />

    <!-- 缩略图区域 -->
    <div class="thumb-img-list">
      <!-- <img :src="item.src" alt v-for="(item,i) in photolist" :key="i" /> -->

      <vue-preview :slides="photolist" @close="handleClose"></vue-preview>
    </div>

    <!-- 内容区域 -->
    <div class="content" v-html="photoinfo.content"></div>

    <!-- 评论子组件 -->
    <!-- 在使用评论子组件的时候，人家必须要接受一个 newsid 的属性 -->
    <comment :newsid="id"></comment>
  </div>
</template>

<script>
//导入评论子组件
import comment from "../sub-components/Comment.vue";


import { Toast } from "mint-ui";

export default {
  data() {
    return {
      photoinfo: {}, //图片信息
      photolist: [], //缩略图的数组
      photolist1: []
    };
  },
  created() {
    this.getPhotoInfo();
    this.getThumblmg();
  },
  methods: {
    getPhotoInfo() {
      //  当调用一个异步方法，同时，这个异步方法的返回值是 Promise 对象的时候，才可以用 await 和 async
      this.$http.get("api/getimageInfo/" + this.id).then(result => {
        if (result.body.status === 0) {
          this.photoinfo = result.body.message[0];
        } else {
          toast("获取图片信息失败！");
        }
      });
    },
    getThumblmg() {
      this.$http.get("api/getthumimages/" + this.id).then(result => {
        //  获取图片的缩略图
        if (result.body.status === 0) {
          //  为每一张图片设置宽高
          result.body.message.forEach(item => {
            item.msrc = item.src;
            item.w = 600;
            item.h = 400;
            item.alt = "picture2";
            item.title = "Image Caption 2";
          });

          this.photolist = result.body.message;
        } else {
          toast("获取缩略图失败!");
        }
      });
    },
    handleClose() {
      console.log("close event");
    }
  },
  props: ["id"],
  components: {
    comment
  }
};
</script>

<style lang="scss" scoped>
.photoinfo-container {
  padding: 3px;
}
.title {
  font-size: 14px;
  text-align: center;
  color: #26a2ff;
}
.info {
  font-size: 13px;
  display: flex;
  justify-content: space-between;
}
.content {
  font-size: 13px;
  line-height: 30px;
}
.thumb-img-list {
  /deep/ .my-gallery {
    //deep深层作用选择器
    display: flex;
    flex-wrap: wrap; //默认换行
    figure {
      width: 30%;
      margin: 5px;
      img {
        width: 120px;
        height: 120px;
        box-shadow: 0 0 8px #999;
        border-radius: 5px;
      }
    }
  }
}
</style>